Q: Which of the following is not considered as an error in JavaScript?
Solution: Division by zero is not an error in JavaScript: it simply returns infinity or negative infinity. There is one exception, however: zero divided by zero does not have a well defined value, and the result of this operation is the special not-a-number value, printed as NaN.
Q: The escape sequence ‘f’ stands for _________
Solution: f is the JavaScript escape sequence that stands for Form feed (u000C). It skips to the start of the next page. (Applies mostly to terminals where the output device is a printer rather than a VDU).
Q: The snippet that has to be used to check if “a” is not equal to “null” is _________
Solution: A strict comparison (e.g., ===) is only true if the operands are of the same type and the contents match. The more commonly-used abstract comparison (e.g. ==) converts the operands to the same type before making the comparison. The not-equal operator !== compares 0 to null and evaluates to either true or false.
Q: The statement a===b refers to _________
Solution: ”===” operator is known as the strict comparison operator. A strict comparison (===) is only true if the operands are of the same type and the contents match.
Q: Assume that we have to convert “false” that is a non-string to string. The command that we use is (without invoking the “new” operator).
Solution: The three approaches for converting to string are: value.toString(),”” + value and String(value). A non-string can be converted in two ways without using a new operator false.toString () and String(false).
Q: What will be the output of the following JavaScript code? function compare() { int num=2; char b=2; if(a==b) return true; else return false; }
Solution: The == convert different type of operands to the same type before making the comparison. A strict comparison results into true value if the operands are of the same type and the contents match.
Q: What will be the output of the following JavaScript code? function equalto() { int num=10; if(num===”10”) return true; else return false; }
Solution: A === operator is only true if the operands are of the same type and the contents match. Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions.
Q: What will be the output of the following JavaScript code? function compare() { int a=1; char b=1; if(a.tostring()===b) return true; else return false; }
Solution: A non string (integer) can be converted to string using .tostring() function. A strict comparison is only true if the operands are of the same type and the contents match. Hence the following code snippet would result into true output.
Q: What will be the output of the following JavaScript code? int a==2; int b=4; int ans=a+b; print(ans);
Solution: The following code will generate into an error output as a comparator operator is used outside of if statement. A single equalto (’=’) operator is used for initialization.
Q: What will be the output of the following JavaScript code? int a=1; if(a!=null) return 1; else return 0;
Solution: != is the not equal to operator. It gives a value of 1 if the two values which are compared are not equal and give 0 if the two values are equal.
You Have Score    | /10 |